package com.scujj.cs6.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scujj.cs6.model.entity.Cities;
import com.scujj.cs6.model.vo.CitiesVo;
import com.scujj.cs6.model.vo.PageVo;
import com.scujj.cs6.service.CitiesService;
import com.scujj.cs6.mapper.CitiesMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author FlanChan
* @description 针对表【cities】的数据库操作Service实现
* @createDate 2025-04-07 11:53:57
*/
@Service
public class CitiesServiceImpl extends ServiceImpl<CitiesMapper, Cities>
    implements CitiesService{


    @Override
    public List<Cities> getAllProvincialCapital() {
        return this.baseMapper.selectAllProvincialCapital();
    }

    @Override
    public PageVo<CitiesVo> pageProvincialCapital(int page, int size) {
        // 计算分页偏移量
        PageVo<CitiesVo> pageVo = new PageVo<>();

        int offset = (page - 1) * size;
        int total = this.countProvincialCapital();
        List<CitiesVo> records = this.baseMapper.pageProvincialCapital(offset , size);

        pageVo.setPage(page);
        pageVo.setSize(size);
        pageVo.setPages(total / size);
        pageVo.setTotal(total);
        pageVo.setRecords(records);
        return pageVo;
    }

    @Override
    public int countProvincialCapital() {
        return this.baseMapper.countProvincialCapital();
    }
}




